// src/main.tsx
import 'antd/dist/reset.css';
import ReactDOM from 'react-dom/client';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import App from './App';
import Register from './Register.tsx';
import Home from './Home.tsx';
import Mine from './Mine/Mine.tsx';
import Community from './Community.tsx';
import Message from './message/Message.tsx'; 
import Setting from './settings/Setting.tsx';
import CategoryDetail from './CategoryDetail.tsx';
import RecipeList from './RecipeList.tsx';
import RecipeDetail from './recipe-detail/RecipeDetail.tsx';
import View_page from './viewpage/View_page'; 
import './App.css';


const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);

root.render(
  <Router>
    <Routes>
      {/* 强制根路径重定向到登录页 */}
      <Route path="/" element={<Navigate to="/login" replace />} />
      
      {/* 认证相关路由 */}
      <Route path="/login" element={<App />} />
      <Route path="/register" element={<Register />} />
      
      {/* 主功能路由 */}
      <Route path="/home" element={<Home />} />
      <Route path="/mine" element={<Mine />} />
      <Route path="/community" element={<Community />} />
      <Route path="/message" element={<Message />} />
      
      {/* 用户相关路由 */}
      <Route path="/user/:id" element={<View_page />} />
      <Route path="/setting" element={<Setting />} />
      
      {/* 食谱相关路由 */}
      <Route path="/CategoryDetail" element={<CategoryDetail />} />
      <Route path="/tag/:tag" element={<RecipeList />} />
      <Route path="/category/:category" element={<RecipeList />} />
      <Route path="/recipe/:id" element={<RecipeDetail />} />
      
      {/* 404 回退路由 - 重定向到首页 */}
      <Route path="*" element={<Navigate to="/home" replace />} />
    </Routes>
  </Router>
);